package com.moleq.db;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {

	public static String DB_NAME = "mpos.db";
	public static String STOCKDB_NAME = "mITY.db";
	private static int VERSION = 1;
    private String errorString;
    private Cursor cursor = null;
    public  SQLiteDatabase db;
	public DatabaseHelper(Context context) {
		super(context, DB_NAME, null, VERSION);	
	}
	
	public DatabaseHelper(Context context,String dbname) {
		super(context, dbname, null, VERSION);	
	}

	@Override
	public void onCreate(SQLiteDatabase arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
		// TODO Auto-generated method stub

	}
	
	public Cursor rawQuery(String sql, String[] selectionArgs){
	  db = this.getWritableDatabase();
		errorString = "";
		try {
			cursor = db.rawQuery(sql, selectionArgs);
		} catch (Exception e) {
			// TODO: handle exception
			 DBError.error = e.getMessage();
			 cursor = null;
		}		
		return cursor;
	}
	
	public String execSQL(String sql){
		 db = this.getWritableDatabase();
		errorString = "";
		try {
			db.execSQL(sql);
		} catch (Exception e) {
			// TODO: handle exception
			errorString = e.getMessage();
		}	
		return errorString;
	}
	
	public String execSQL(String sql, Object[] selectionArgs){
		 db = this.getWritableDatabase();
		errorString = "";
		try {
			db.execSQL(sql,selectionArgs);
		} catch (Exception e) {
			// TODO: handle exception
			errorString = e.getMessage();
		}	
		return errorString;
	}
}